<?php
/**
 * Created by PhpStorm.
 * User: taoyufang
 * Date: 17/12/05
 * Time: 15:37
 */

class TaskActionModel extends MY_Model{

    protected $table = 't_task_action';

    public function __construct(){
        parent::__construct();
    }

    /**
     * 获取操作列表
     * name: getList
     * @param string $like
     * @param int $page
     * @param int $pagesize
     * @return array
     * @Author:taiyang
     */
    public function getActionList($like = '',$page = 1, $pagesize = 30,$return=''){
        $sql="select * from ".$this->table." WHERE 1 ";
        if(!empty($like)){
            $sql .= " and (`name` like '%".$like."%' or `desc` like '%".$like."%' or `code` like '%".$like."%') ";
        }
        if($page != 0){ //等于0 不分页
            $index = ($page - 1) * $pagesize > 0 ? ($page - 1) * $pagesize : 0;
            $sql.= " limit ".$index.",".$pagesize;
        }
        $res= $this->query_sql_list($sql);
        $res_x=array();
        foreach($res as $k=>$v){
            $res_x[$v['code']]=$v;
        }
        if(!empty($return)){return $res_x;}
        return $res;
    }

    /**
     * 获取操作总数
     * name: getListCnt
     * @param string $like
     * @return int
     * @Author:taiyang
     */
    public function getListCnt($like = ''){
        $sql="select count(*) from ".$this->table." WHERE 1 ";
        if(!empty($like)){
            $sql .= " and (`name` like '%".$like."%' or `desc` like '%".$like."%' or `code` like '%".$like."%') ";
        }
        return $this->query_sql_count($sql);
    }


}